home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBGRX100.ARJ / XWD2FNA.C < prev   
C/C++ Source or Header  |  1992-01-30  |  2KB  |  83 lines

  1. #include <X11/XWDFile.h>
  2. #include <stdio.h>
  3.  
  4. main(argc,argv)
  5.     int  argc;
  6.     char **argv;
  7. {
  8.     XWDFileHeader hdr;
  9.     FILE *inp;
  10.     char *buff,*p;
  11.     int ii,jj;
  12.     int rasterx,rastery;
  13.     int offset;
  14.     int rows,cols;
  15.     int chrx,chry;
  16.     int fg,bg;
  17.  
  18.     if(argc > 1) {
  19.             if((inp = fopen(argv[1],"r")) == NULL) {
  20.             fprintf(stderr,"usage: fconv <input file>\n");
  21.             exit(1);
  22.         }
  23.     }
  24.     else inp = stdin;
  25.     fread(&hdr,sizeof(hdr),1,inp);
  26.     fprintf(stderr,"bits per pixel: %d\n",hdr.bits_per_pixel);
  27.     fprintf(stderr,"bytes per line: %d\n",hdr.bytes_per_line);
  28.     fprintf(stderr,"pixmap width: %d\n",hdr.pixmap_width);
  29.     fprintf(stderr,"pixmap height: %d\n",hdr.pixmap_height);
  30.     fseek(inp,-(hdr.bytes_per_line * hdr.pixmap_height),2);
  31.     buff = (char *)malloc(hdr.bytes_per_line * hdr.pixmap_height);
  32.     fread(buff,hdr.bytes_per_line,hdr.pixmap_height,inp);
  33.     fclose(inp);
  34.     offset = hdr.bytes_per_line;
  35.     fg = buff[0];
  36.     bg = buff[offset + 1];
  37.     fprintf(stderr,"offset = %d, fg = %d, bg = %d\n",offset,fg,bg);
  38.     p = &buff[offset];
  39.     while(*++p != fg);
  40.     rasterx = ii = p - &buff[offset];
  41.     fprintf(stderr,"width = %d, %d %d\n",ii,buff[offset],buff[offset + ii]);
  42.     p = &buff[1];
  43.     while(*(p += offset) != fg);
  44.     rastery = (p - &buff[1]) / offset;
  45.     chrx = rasterx - 3;
  46.     chry = rastery - 3;
  47.     fprintf(stderr,"rasterx: %d rastery: %d, chrx: %d chry: %d\n",
  48.         rasterx,rastery,chrx,chry);
  49.     cols = hdr.pixmap_width / rasterx;
  50.     rows = hdr.pixmap_height / rastery;
  51.     if(rows > (128 / cols)) rows = (128 / cols);
  52.  
  53.     fprintf(stderr,"cols = %d rows = %d\n",cols,rows);
  54.     
  55.     printf("minchar  0\n");
  56.     printf("maxchar  %d\n",(cols * rows) - 1);
  57.     printf("width    %d\n",chrx);
  58.     printf("height   %d\n",chry);
  59.     printf("family   X_misc\n\n");
  60.     for(ii = 0; ii < rows; ii++) {
  61.         for(jj = 0; jj < cols; jj++) {
  62.             int x,y,kk,ll;
  63.  
  64.         x = jj * rasterx + 2;
  65.         y = ii * rastery + 2;
  66.         p = &buff[y * offset + x];
  67.         for(kk = 0; kk < chry; kk++) {
  68.             for(ll = 0; ll < chrx; ll++) {
  69.             putchar((p[kk * offset + ll] == fg) ? '#' : '.');
  70.             }
  71.             putchar('\n');
  72.         }
  73.         putchar('\n');
  74.         }
  75.     }
  76.         
  77.     exit(0);
  78. }
  79.     
  80.  
  81.  
  82.     
  83.